#!/usr/bin/evn python
# -*- coding: utf-8 -*-
"""
description:  using
author: justbk
date: 2021/7/5
modify_records:
    - 2021/7/5 justbk create this file
"""
import os
from file_loading import LoadBenchmarkSqlLog
from analyze import LogAnalyzeLineChain, ArrayTimeStampDesc, TimestampCalc


class Runner:
    def __init__(self):
        self.record_dispatch = TimestampCalc()

    def run(self, file=None):
        if file is None:
            file = self.get_default_log()
        chains = LogAnalyzeLineChain.generate_chains(self.record_dispatch)
        for line in LoadBenchmarkSqlLog(file).get_all_lines():
            chains.doit(line)

    def output(self):
        results = ArrayTimeStampDesc()
        results.output()

    @classmethod
    def get_default_log(cls):
        root_path = os.path.dirname(os.path.abspath(__file__))
        return os.path.join(root_path, 'benchmarksql-trace.log')

    @classmethod
    def get_proxy_log(cls):
        root_path = os.path.dirname(os.path.abspath(__file__))
        return os.path.join(root_path, 'proxy_trace', 'benchmarksql-trace.log')

    @classmethod
    def get_proxy_portal_log(cls):
        root_path = os.path.dirname(os.path.abspath(__file__))
        return os.path.join(root_path, 'proxy_trace_portal', 'benchmarksql-trace.log')



if __name__ == '__main__':
    for file in [Runner.get_default_log(), Runner.get_proxy_log(), Runner.get_proxy_portal_log()]:
        print('----------------- {}'.format(file))
        ArrayTimeStampDesc.clear()
        runner = Runner()
        runner.run(file)
        runner.output()


